<?php

class MySQLConnect
{
	
	private $mysqli;

	public function __construct( $host, $username, $password )
	{
		
		$this->mysqli = new mysqli ( $host, $username, $password );
		
		/* check connection */
		if ( mysqli_connect_errno () )
		{
			trigger_error ( 'Database connection failure: Username/Password was incorrect.', E_USER_ERROR );
			exit ();
		} else
		{
			return $this->mysqli;
		}
	}

	public function execute( $sql )
	{
		if ( $result = $this->mysqli->query ( $sql ) )
		{
			/* fetch associative array */
			while ( $row = $result->fetch_assoc () )
			{
				$array[] = $row;
			}
			
			/* free result set */
			$result->close ();
		}
		
		/* close connection */
		$this->mysqli->close ();
		
		return $array;
	}

	public function dump( $var, $title )
	{
		print "<h4>$title</h4>";
		print "<pre>";
		print_r ( $var );
		print "</pre>";
	}

	/**
	 * @return unknown
	 */
	public function getMysqli()
	{
		return $this->mysqli;
	}

	/**
	 * @param unknown_type $mysqli
	 */
	public function setMysqli( $mysqli )
	{
		$this->mysqli = $mysqli;
	}

}
?>